#ifndef __PULLSDK_H__
#define __PULLSDK_H__

#include <platform.h>

//#define TIME_NOW		("TIME_NOW")


#define NO_KEY -1
#define ERROR_FORMAT_DATE	(-201)
#define ERROR_TIME_TAG		(-202)

#ifdef __cplusplus
extern "C"{
#endif


	//连接到设备，连接成功后返回连接句柄
	//Connected to the device, connected to return after successful connection handle
	UDK_DLLIMPORT UDK_HANDLE UDK_API 
		PullSDKConnect(const char *Parameters	/*通过Parameter参数指定连接选项，如下列例子：
						  (Parameter parameters specified by connectivity options, such as the following examples:)
						  "protocol=RS232,port=COM1,baudrate=115200bps,timeout=1200000,passwd=0"
						  "protocol=RS485,port=COM2,baudrate=115200bps,deviceid=1,timeout=1200000,passwd=0"
						  "protocol=UDP,ipaddress=192.168.1.201,port=4370,timeout=1200000,passwd=0"
						  "protocol=HTTP,ipaddress=192.168.1.201,port=80,name=12345,passwd=12345"
						  "protocol=HTTPS,ipaddress=192.168.1.201,port=80,name=12345,passwd=12345"
						 */
		       );

    UDK_HANDLE UDK_API Connect(const char *Parameters);

	//断开与设备的连接(Disconnect the equipment connected)
	UDK_DLLIMPORT void UDK_API 
		PullSDKDisconnect(UDK_HANDLE h);

    void UDK_API Disconnect(UDK_HANDLE Handle);

	//查询设备中的数据，返回数据的字符长度
	//(For equipment in the data, the data back to the length of the characters)
	UDK_DLLIMPORT int UDK_API 
		PullSDKGetDeviceData(UDK_HANDLE h, 
				char *Buffer,		//用于接收返回数据的缓冲区，返回的数据是文本格式的，可能是多条记录，
				//各条记录之间用\r\n分隔，各个字段之间用\t分隔 
				//To receive the data back to the buffer zone, the data is returned to the text format,
				//may be a number of records,All records with \ r \ n separation, 
				//between the various fields with \ t separated

				int BufferSize,		//用于接收返回数据的缓冲区大小(For receiving data back to the size of the buffer)
				const char *TableName,	//数据表名(Table name)
				const char *FieldNames,	//字段名列表，多个字段之间用逗号号分开，“*”表示全部字段，此时数据字段的第一行是字段名
				//Fields of the list, a number of fields, separated by commas, 
				//"*" that all the fields, when data fields is the first line of field
				const char *Filter,		/*返回数据的条件，可以是如下几种方式的字符串：
								  <字段名> = <值>
								  <字段名> IN (<逗号分隔的多个值列表>)
								  <字段名> BETWEN (<最小值>,<最大值>) 或 <字段名> BETWEN <最小值> TO <最大值>
								  <字段名> > <小值>
								  <字段名> >= <最小值>
								  <字段名> < <大值>
								  <字段名> =< <最大值>
								  <字段名> LIKE <前导字符串>*
								  <字段名> LIKE *<后缀字符串>
								 */
		/*Data returned to the conditions, it could be several ways of the string is as follows: 
		  <Field of> = <value> 
		  <Field names> IN (<comma-separated list of multiple values>) 
		  <Field names> BETWEN (<minimum>, <Max>) or <field names> BETWEN <minimum> TO <Max> 
		  <Field names>> <small value> 
		  <Field names>> = <minimum> 
		  <Field names> <<great value> 
		  <Field of> = <<Max> 
		  <Field names> LIKE <leader string> * 
		  <Field names> LIKE * <suffix string>
		 */
		const char *Options
			);
     int UDK_API GetDeviceData(void *Handle,
        char *Buffer,		
        int BufferSize,		
        const char *TableName,	
        const char *FieldNames,	
        const char *Filter,
        const char *Options
        );

	//查询设备中的数据记录数，返回指定数据的记录数
	UDK_DLLIMPORT int UDK_API 
		PullSDKGetDeviceDataCount(UDK_HANDLE h, 
				const char *TableName,	//数据表名
				const char *Filter,		//返回数据的条件，其含义同 DataQuery 函数
				const char *Options		/* 进行查询的选项。这些选项是 以逗号分隔的 项=值 对, 可能的值有：
								   IgnoreCase	条件数据是否忽略大小写
								 */
				//Query options. These options is a comma-separated values of the = right, the possible values are: 
				//		MaxReturn specify up to return to the record number of 
				//		IgnoreCase conditions neglect case data
				);

        int UDK_API GetDeviceDataCount(UDK_HANDLE Handle,
            const char *TableName,
            const char *Filter,
            const char *Options);

	//设备控制
	UDK_DLLIMPORT int UDK_API 
		PullSDKControlDevice(UDK_HANDLE h,
				long OperationID,
				long Param1,
				long Param2,	//控制,地址 1234
				long Param3,	//控制参数
				long param4,
				const char *Options
			     );

        int UDK_API ControlDevice(void *Handle,
            UDK_LONG OperationID,
            UDK_LONG Param1,	
            UDK_LONG Param2,
            UDK_LONG Param3,
            UDK_LONG Param4,
            const char *Options);

	//增加数据到设备中,返回设备成功新增的数据记录数
	//Increase the data to equipment, equipment returned to the success of the new data records
	UDK_DLLIMPORT int UDK_API 
		PullSDKSetDeviceData(UDK_HANDLE h, 
				const char *TableName,	//数据表名 (Table name)
				const char *Datas,		/*数据记录表示，数据是文本格式的，可以多条记录之间用\r\n分隔，各个“字段=值”对之间用逗号分隔。
								  例如：
								  (Data recording, data is a text format, you can use a number of records \ r \ n 
								  separated, the "field = value" of between separated by commas. For example:)
								  PIN=12345,Name=Richard,Password=2298
								  PIN=12346,Name=王玲玲,Password=2,Gender=Female
								  PIN=1
								  如果一条新数据的某些字段没有指定值，则固件会根据具体的字段定义使用默认值；
								  (If a new data do not specify the value of certain fields, 
								  the firmware will be based on specific definition of the field to use the default;
								 */
		const char *Options	/*扩展属性
					 */
			);
    int UDK_API SetDeviceData(UDK_HANDLE Handle,
        const char *TableName,
        const char *Datas,		
        const char *Options	
    );


				//删除设备中的数据
				//To delete the data in the equipment
				UDK_DLLIMPORT int UDK_API 
					PullSDKDeleteDeviceData(UDK_HANDLE h, 
							const char *TableName,	//要删除数据所在的数据表名 (Table name)
							const char *Datas,		//要删除数据的条件，其含义同 DataQuery 函数 
							//(To update the data of the conditions, meaning the same function DataQuery)
							const char *Options		/* 进行查询的选项。这些选项是 以逗号分隔的 项=值 对, 可能的值有：
											   Query options. These options is a comma-separated values of the = right, the possible values are:
											   MaxReturn	指定最多返回的记录数 (Specify up to return to the record number of)
											   IgnoreCase	条件数据是否忽略大小写 (Whether the conditions of neglect case-sensitive data)
											 */
							);

        int UDK_API DeleteDeviceData(UDK_HANDLE Handle,
            const char *TableName,
            const char *Datas,
            const char *Options	
            );

	//查询设备信息，返回值为数据的长度
	//For information equipment, the return value for the length of data
	UDK_DLLIMPORT int UDK_API 
		PullSDKGetDeviceParam(UDK_HANDLE h, 
				char *Buffer,		//用于接收返回数据的缓冲区，返回的数据是文本格式的，如果返回的是多条信息，
				//各条信息之间用\r\n分隔，每条信息是一“信息项=值”对
				//To receive the data back to the buffer zone, the data is returned to the text, 
				//if the return is the number of information, Between all of the information 
				//used \ r \ n separated, each message is an "information = value "					
				int BufferSize,		//用于接收返回数据的缓冲区大小(For receiving data back to the size of the buffer zone)
				const char *Items	//要查询的设备信息项名称表，多个名称之间可以用逗号分开。当前可用的信息项参看附表
				//For the information of the name of the equipment table, 
				//a number of names can be used between the comma separated. Of the information currently available See Schedule
			      );
        int UDK_API GetDeviceParam(UDK_HANDLE Handle, char *Buffer, int BufferSize,	const char *Items);

	//设置设备信息(Information set up equipment)
	UDK_DLLIMPORT int UDK_API 
		PullSDKSetDeviceParam(UDK_HANDLE h, 
				const char *ItemAndValues	/*“信息项=值”对，多个项之间用\r\n分隔，例如
								  ("Information = value" , between multiple items with \ r \ n separated, for example,)
								  System.PlayVoice="1.wav"	播放语音文件 1.wav (Play audio files 1.wav)
								  Options.Baudrate=115200		设置232/485的通信波特率 (The communication baud rate settings 232/485)
								  System.VideoFile=BASE64:xxx	上传宣传视频文件 (Upload video files publicity)
								 */
			      );
        int UDK_API SetDeviceParam(UDK_HANDLE Handle, const char *ItemAndValues);

	UDK_DLLIMPORT int UDK_API 
		PullSDKBase64WriteToBMP(const char *base64, const char *fileBmp);
	//UDK_DLLIMPORT char* UDK_API GetRealTimeTag(void *Handle, const char *TableName);
	//UDK_DLLIMPORT int UDK_API SetRealTimeTag(void *Handle, const char *TableName, const char *strTag);
	//UDK_DLLIMPORT int UDK_API GetRealTimeDatas(void *Handle, const char *TableName, const char *FieldsName, char *Buffer, int BufferSize);
	//UDK_DLLIMPORT int UDK_API SynTime(void *Handle);
	UDK_DLLIMPORT int UDK_API 
		PullSDKGetRTLog(UDK_HANDLE h, char *Buffer, int BufferSize);

    int UDK_API GetRTLog(UDK_HANDLE Handle, char *Buffer, int BufferSize);

	UDK_DLLIMPORT int UDK_API 
		PullSDKSearchDevice(char *CommType,char *Address, char *Buffer,int *BufferSize);

    int UDK_API SearchDevice(char *CommType,char *Address, char *Buffer,int *BufferSize);

	UDK_DLLIMPORT int UDK_API 
		PullSDKModifyIPAddress(char *CommType, const char *Address, char *Buffer,int BufferSize);

    int UDK_API ModifyIPAddress(char *CommType, const char *Address, char *Buffer,int BufferSize);

	UDK_DLLIMPORT int UDK_API PullSDKLastError();

    int UDK_API LastError();

	UDK_DLLIMPORT int UDK_API 
		PullSDKSetDeviceFileData(UDK_HANDLE h,	const char *FileName,	
				char *Buffer,int BufferSize,const char *Options	);

    int UDK_API SetDeviceFileData(UDK_HANDLE Handle,
        const char *FileName,
        char *Buffer,		
        int BufferSize,			
        const char *Options);


	UDK_DLLIMPORT int UDK_API 
		PullSDKGetDeviceFileData(UDK_HANDLE h,	char *Buffer,int *BufferSize,
				const char *FileName,const char *Options);

    int UDK_API GetDeviceFileData(UDK_HANDLE Handle,
        char *Buffer,		
        int *BufferSize,		
        const char *FileName,	
        const char *Options
        );

     UDK_DLLIMPORT int PullSDKGetTableStruct(UDK_HANDLE Handle, char *buffer, int buflen);

     UDK_DLLIMPORT int PullSDKSetTableStruct(UDK_HANDLE Handle, const char *table_struct);

	 UDK_DLLIMPORT int UDK_API PullSDKSetAppid(UDK_HANDLE h, const char *appid);

	 UDK_DLLIMPORT int UDK_API PullSDKMobileAtt(UDK_HANDLE h, int operate, char *premeters, char *Buffer,int* BufferLength);

	 UDK_DLLIMPORT int UDK_API PullSDKSetDownloadProcessCallBack(UDK_HANDLE h, void *pCallBackFun);

	 UDK_DLLIMPORT int UDK_API PullSDKResetDeviceExt(UDK_HANDLE h, char *parameters);
#ifdef __cplusplus
}
#endif
#endif 
